home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / comm2 / stat_com.zip / STAT.C < prev    next >
Text File  |  1990-11-10  |  6KB  |  246 lines

  1. /* stat.c */
  2.  
  3. #include "dos.h"
  4. #include "conio.h"
  5. #include "string.h"
  6. #include "stdio.h"
  7.  
  8. #define COM1 0x3F8        /* COM1 Base    */
  9. #define COM2 0x2F8        /* COM2 Base    */
  10. #define COM3 0x3E8        /* COM3 Base    */
  11. #define COM4 0x2E8        /* COM4 Base    */
  12. #define TOUCH 0x2D8       /* Pro-ED       */
  13. #define LASER 0x2E0       /* Pro-ED       */
  14.  
  15. main (int argc, char **argv)
  16. {
  17.   void aerror(void);
  18.   unsigned com,status;
  19.   int onoff;
  20.   static char com1[] = "03F8";
  21.   static char com2[] = "02F8";
  22.   static char com3[] = "03E8";
  23.   static char com4[] = "02E8";
  24.   static char coms1[] = "COM1";
  25.   static char coms2[] = "COM2";
  26.   static char coms3[] = "COM3";
  27.   static char coms4[] = "COM4";
  28.   char coms[5];
  29.   char comss[6];
  30.  
  31.   if (argc < 2) {
  32.     aerror();
  33.     }
  34.  
  35.   if ( (strcmpi( *(argv+1),"com1") ) == 0 ) {
  36.     com = COM1;
  37.     strcpy(coms,com1);
  38.     strcpy(comss,coms1);
  39.     }
  40.   else {
  41.     if ( (strcmpi( *(argv+1),"com2") ) == 0 ) {
  42.       com = COM2;
  43.       strcpy(coms,com2);
  44.       strcpy(comss,coms2);
  45.     }
  46.     else {
  47.       if ( (strcmpi( *(argv+1),"com3") ) == 0 ) {
  48.         com = COM3;
  49.         strcpy(coms,com3);
  50.         strcpy(comss,coms3);
  51.         }
  52.       else {
  53.         if ( (strcmpi( *(argv+1),"com4") ) == 0 ) {
  54.           com = COM4;
  55.           strcpy(coms,com4);
  56.           strcpy(comss,coms4);
  57.           }
  58.         else {
  59.           if ( (strcspn(argv[1],"Pp")) == 0 ) {
  60.             if ( (strlen(argv[1]) > 2) & (strlen(argv[1]) < 6) ) {
  61.               strcpy(comss,"PORT");
  62.               strcpy(coms,argv[1]+1);
  63.               sscanf (coms," %x",&com);
  64.             }
  65.             else {
  66.               aerror();
  67.             }
  68.           }
  69.           else {
  70.             aerror();
  71.           }
  72.         }
  73.       }
  74.     }
  75.   }
  76.  
  77.   if (argc > 3) {
  78.     if ( (strcmpi( *(argv+3),"on") ) == 0 ) {
  79.       onoff = 1;
  80.     }
  81.     else {
  82.       if ( (strcmpi( *(argv+3),"off") ) == 0 ) {
  83.         onoff = 0;
  84.       }
  85.       else {
  86.         aerror();
  87.       }
  88.     }
  89.     if ( (strcmpi( *(argv+2),"int") ) == 0 ) {
  90.       inter(com,onoff);
  91.     }
  92.     else {
  93.       if ( (strcmpi( *(argv+2),"dtr") ) == 0 ) {
  94.         dtronoff(com,onoff);
  95.       }
  96.       else {
  97.         if ( (strcmpi( *(argv+2),"rts") ) == 0 ) {
  98.           rtsonoff(com,onoff);
  99.         }
  100.         else {
  101.           aerror();
  102.         }
  103.       }
  104.     }
  105.   }
  106.   else {
  107.     if (argc == 3) aerror();
  108.   }
  109.  
  110.   stat(com,coms,comss);
  111.   exit(0);
  112. }
  113.  
  114. /* Turn RTS ON or OFF at selected port */
  115. rtsonoff(unsigned port, int onoff)
  116. {
  117.   unsigned status;
  118.  
  119.   if ( onoff == 1 ) {
  120.     status = inp(port+4);
  121.     status = status | 0x02;
  122.     outp(port+4,status);
  123.   }
  124.   else {
  125.     status = inp(port+4);
  126.     status = status & 0xFD;
  127.     outp(port+4,status);
  128.   }
  129.   return;
  130. }
  131.  
  132. /* Turn DTR ON or OFF at selected port */
  133. dtronoff(unsigned port, int onoff)
  134. {
  135.   unsigned status;
  136.  
  137.   if ( onoff == 1 ) {
  138.     status = inp(port+4);
  139.     status = status | 0x01;
  140.     outp(port+4,status);
  141.   }
  142.   else {
  143.     status = inp(port+4);
  144.     status = status & 0xFE;
  145.     outp(port+4,status);
  146.   }
  147.   return;
  148. }
  149.  
  150. /* Turn interrupts ON or OFF at selected port */
  151. inter(unsigned port, int onoff)
  152. {
  153.   unsigned status;
  154.  
  155.   if ( onoff == 1 ) {
  156.     status = inp(port+4);
  157.     status = status | 0x08;
  158.     outp(port+4,status);
  159.   }
  160.   else {
  161.     status = inp(port+4);
  162.     status = status & 0xF7;
  163.     outp(port+4,status);
  164.   }
  165.   return;
  166. }
  167.  
  168. /* stat() */
  169. /* print status of the 8250 MODEM Control register */
  170. stat(unsigned port, char *coms, char *comss)
  171. {
  172.   int status,mstatus,mcontrol,testit;
  173.   printf("  \n");
  174.   status = inp(port + 2);
  175.   status = status & 0xF8;
  176.   if ( status ) {
  177.     printf("Serial port on %s %s is not installed.\n",comss,coms);
  178.     return;
  179.   }
  180.   mstatus = inp(port + 6);
  181.   mcontrol = inp(port + 4);
  182.   printf("MODEM status and MODEM control on %s %s is %X, %X.\n",
  183.   comss,coms,mstatus,mcontrol);
  184.   testit = mstatus & 0x80;
  185.   if (testit)
  186.     printf("  DCD is on,");
  187.   else
  188.     printf("  DCD is off,");
  189.  
  190.   testit = mstatus & 0x20;
  191.   if (testit)
  192.     printf("  DSR is on,");
  193.   else
  194.     printf("  DSR is off,");
  195.  
  196.   testit = mstatus & 0x10;
  197.   if (testit)
  198.     printf("  CTS is on,");
  199.   else
  200.     printf("  CTS is off,");
  201.  
  202.   testit = mcontrol & 1;
  203.   if (testit)
  204.     printf("  DTR is on,");
  205.   else
  206.     printf("  DTR is off,");
  207.  
  208.   testit = mcontrol & 2;
  209.   if (testit)
  210.     printf("  RTS is on.\n");
  211.   else
  212.     printf("  RTS is off.\n");
  213.  
  214.   testit = mcontrol & 8;
  215.   if (testit)
  216.     printf("  INTERRUPTS are enabled.\n");
  217.   else
  218.     printf("  INTERRUPTS are disabled.\n");
  219.   return;
  220. }
  221.  
  222. void aerror(void)
  223. {
  224.   printf(" \n");
  225.   printf("You need at least 1 argument for the the STAT program.   \n");
  226.   printf("  The first argument is the name of the COM port or the  \n");
  227.   printf("  the base address of the COM port whose status you wish \n");
  228.   printf("  to modify or display.  The second and third parameters \n");
  229.   printf("  are optional and must appear together.  They specify   \n");
  230.   printf("  the items which can be turned ON or OFF.               \n");
  231.   printf("                                                         \n");
  232.   printf("  SYNTAX:                                                \n");
  233.   printf("              ┌       ┐ ┌     ┐ ┌     ┐                  \n");
  234.   printf("         STAT │ COM1  │ │ INT │ │ ON  │                  \n");
  235.   printf("              │ COM2  │ │ RTS │ │ OFF │                  \n");
  236.   printf("              │ COM3  │ │ DTR │ └     ┘                  \n");
  237.   printf("              │ COM4  │ └     ┘                          \n");
  238.   printf("              │ PNNNN │                                  \n");
  239.   printf("              └       ┘                                  \n");
  240.   printf("  Where NNNN is a PORT address.                          \n");
  241.   printf("                                                         \n");
  242.   printf("  EXAMPLE --> C>stat com1 int on                         \n");
  243.   printf("              C>stat p3f8 rts off <--- port address 3F8  \n");
  244.   exit(0);
  245. }
  246.